package com.quanyan.stadium.service.gameRules.impl;

import com.alibaba.dubbo.common.utils.CollectionUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.quanyan.api.APIResponse;
import com.quanyan.club.entity.RespClubPlainInfo;
import com.quanyan.common.utils.DateUtils;
import com.quanyan.stadium.api.req.ReqGameSchedule;
import com.quanyan.stadium.api.req.ReqRecordGameScheduleResult;
import com.quanyan.stadium.api.resp.v2.RankGameTeam;
import com.quanyan.stadium.biz.BizGameSystemDao;
import com.quanyan.stadium.constants.GameConstants;
import com.quanyan.stadium.entity.*;
import com.quanyan.stadium.entity.vo.Club;
import com.quanyan.stadium.entity.vo.GameTeam;
import com.quanyan.stadium.entity.vo.User;
import com.quanyan.stadium.entity.vo.VDefinedGameSchedule;
import com.quanyan.stadium.enums.GameScheduleScoreEnum;
import com.quanyan.stadium.enums.GameSystemConfigEnum;
import com.quanyan.stadium.enums.errorEnum.RecordScoreErrorEnum;
import com.quanyan.stadium.mapper.TbGameScheduleAddendumMapper;
import com.quanyan.stadium.mapper.TbGameScheduleMapper;
import com.quanyan.stadium.service.commonComponent.BaseService;
import com.quanyan.stadium.service.commonComponent.GameMQProduct;
import com.quanyan.stadium.service.commonComponent.GameMsgPush;
import com.quanyan.stadium.service.commonComponent.OfficialGameCache;
import com.quanyan.stadium.service.gameRules.GameScheduleService;
import com.quanyan.stadium.service.gameRules.GameSystemServiceEight;
import com.quanyan.stadium.transfer.GameConfigTransfer;
import com.quanyan.user.response.RespUserInfoBase;
import org.apache.commons.beanutils.BeanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.util.*;

/**
 * @author songzj
 * @date 16/4/11-14:42
 */

@Service("gameScheduleService")
public class GameScheduleServiceImpl implements GameScheduleService {

    @Autowired
    private BizGameSystemDao bizGameSystemDao;

    @Autowired
    private TbGameScheduleMapper tbGameScheduleMapper;

    @Autowired
    private TbGameScheduleAddendumMapper tbGameScheduleAddendumMapper;

    @Autowired
    private BaseService baseService;

    @Autowired
    private OfficialGameCache officialGameCache;

    @Autowired
    private GameMQProduct gameMQProduct;

    @Autowired
    private GameMsgPush gameMsgPush;

    @Autowired
    private GameConfigTransfer gameEventTransfer;

    @Autowired
    private GameSystemServiceEight gameSystemServiceEight;

    private static final Logger logger = LoggerFactory.getLogger(GameScheduleServiceImpl.class);

    @Override
    public APIResponse<?> recordGameScheduleResult(Integer uid, ReqRecordGameScheduleResult req) {
        TbGameEvent tbGameEvent = bizGameSystemDao.selectTbGameEvent(req.getGameEventId());
        List<VDefinedGameSchedule> currentGameSchedules = bizGameSystemDao.selectVDefinedGameScheduleById(req.getGameScheduleId());
        int flag = validateRecordAuth(req, tbGameEvent, currentGameSchedules);
        if (flag > 0) {
            return APIResponse.returnFail(RecordScoreErrorEnum.getMsgById(flag));
        }
        TbGameSchedule tbGameSchedule = new TbGameSchedule();
        boolean isDispute = false, isUser = false, isDoubleRecord = false;
        Byte myTeamType = 0;
        List<Byte> recordTeamType = new ArrayList<>();
        if (req.getType() == 0) {
            VDefinedGameSchedule vTemp = new VDefinedGameSchedule();
            for (VDefinedGameSchedule  vDefinedGameSchedule : currentGameSchedules) {
                if (tbGameEvent.getGameTeamType() == GameConstants.TEAM_TYPE_CLUB) {
                    List<TbGameClubTeamUser> clubIds = bizGameSystemDao.queryTbGameClubTeamUserByUid(tbGameEvent.getId(), uid);
                    if (null!=clubIds && clubIds.size() >0) {   //大球类支持第一队员录入
                        isUser = true;
                        TbGameClubTeamUser user = clubIds.get(0);
                        if (user.getGameTeamId().equals(vDefinedGameSchedule.getEventTeamId())) {
                            if (null != vDefinedGameSchedule.getRecordScore()) {
                                isDoubleRecord = true;
                            }
                            vTemp = vDefinedGameSchedule;
                            break;
                        }
                    }
                }else if (tbGameEvent.getGameTeamType() == GameConstants.TEAM_TYPE_PERSON) {
                    if ((gameEventTransfer.getGameCategoryById(tbGameEvent.getGameCategoryType().intValue()).getMinNum() == 2 &&
                            gameEventTransfer.getGameCategoryById(tbGameEvent.getGameCategoryType().intValue()).getMaxNum() == 2)) {
                        if (null != vDefinedGameSchedule.getRecordScore()) {
                            recordTeamType.add(vDefinedGameSchedule.getType());
                        }
                        if (vDefinedGameSchedule.getUid().intValue() == uid.intValue()) {
                            vTemp = vDefinedGameSchedule;
                            isUser = true;
                            myTeamType = vDefinedGameSchedule.getType();
                        }
                    }else {
                        if (vDefinedGameSchedule.getUid().intValue() == uid.intValue()) {
                            isUser = true;
                            if (null != vDefinedGameSchedule.getRecordScore()) {
                                isDoubleRecord = true;
                            }
                            vTemp = vDefinedGameSchedule;
                            break;
                        }
                    }
                }else {
                }
            }
            if (recordTeamType.contains(myTeamType)) {
                isDoubleRecord = true;
            }
            if (!isUser) {            //校验用户合法性;
                return APIResponse.returnFail(RecordScoreErrorEnum.RECORD_SCORE_LIST_ERROR_7.getLabel());
            }
            if (isDoubleRecord) {   //校验用户是否再次已经录入
                return APIResponse.returnFail(RecordScoreErrorEnum.RECORD_SCORE_LIST_ERROR_8.getLabel());
            }
            TbGameScheduleAddendum addendum = new TbGameScheduleAddendum();
            addendum.setId(vTemp.getId());
            if (null !=req.getScores()) {
                addendum.setRecordScore(req.getScores());
            }
            tbGameScheduleAddendumMapper.updateByPrimaryKeySelective(addendum);
            tbGameSchedule.setId(vTemp.getGameScheduleId());
            if (null !=req.getScores()) {
                tbGameSchedule.setFinalScore(req.getScores());
            }
            if (vTemp.getStatus() == GameConstants.RECORD_WAIT) {
                tbGameSchedule.setStatus(GameConstants.RECORD_WAIT_SURE);
                tbGameSchedule.setIsWin(req.getIsWin());
            }else if (vTemp.getStatus() == GameConstants.RECORD_WAIT_SURE) {
                if (vTemp.getIsWin().byteValue() == req.getIsWin().byteValue()) {
                    tbGameSchedule.setStatus(GameConstants.RECORD_SUCCESS);
                }else {
                    isDispute = true;
                    tbGameSchedule.setStatus(GameConstants.RECORD_FAIL);
                }
                tbGameSchedule.setIsWin(req.getIsWin());
            }else {
            }
        } else {
            tbGameSchedule.setId(req.getGameScheduleId());
            tbGameSchedule.setFinalScore(req.getScores());
            tbGameSchedule.setStatus(GameConstants.RECORD_SUCCESS);
            tbGameSchedule.setIsWin(req.getIsWin());
        }
        bizGameSystemDao.updateTbGameSchedule(tbGameSchedule);

        afterRecordScore(isDispute, req, tbGameEvent, uid, req.getIsWin());

        return APIResponse.returnSuccess();
    }

    @Override
    public int userRecordScoreV2(Integer uid, ReqRecordGameScheduleResult req) {
        TbGameEvent tbGameEvent = bizGameSystemDao.selectTbGameEvent(req.getGameEventId());
        List<VDefinedGameSchedule> currentGameSchedules = bizGameSystemDao.selectVDefinedGameScheduleById(req.getGameScheduleId());
        int flag = validateRecordAuth(req, tbGameEvent, currentGameSchedules);

        // 校验失败，不能录入比分
        if (flag > 0) {
            return flag;
        }

        TbGameSchedule tbGameSchedule;
        if (req.getType() == 0) {
            tbGameSchedule = bizGameSystemDao.selectTbGameScheduleById(req.getGameScheduleId());
            if (null != tbGameSchedule && tbGameSchedule.getStatus().byteValue() == GameConstants.RECORD_SUCCESS) {
                logger.info("userRecordScoreV2 Game schedule score has been entered.");
                flag = 1;
                return flag;
            }
        }

        tbGameSchedule = new TbGameSchedule();
        tbGameSchedule.setFinalScore(req.getScores());
        tbGameSchedule.setId(req.getGameScheduleId());
        tbGameSchedule.setFinalScore(req.getScores());
        tbGameSchedule.setStatus(GameConstants.RECORD_SUCCESS);
        tbGameSchedule.setIsWin(req.getIsWin());

        bizGameSystemDao.updateTbGameSchedule(tbGameSchedule);

        afterRecordScore(false, req, tbGameEvent, uid, req.getIsWin());

        return flag;
    }

    public int validateRecordAuth(ReqRecordGameScheduleResult req, TbGameEvent tbGameEvent, List<VDefinedGameSchedule> currentGameSchedules){
        int result = -1;
        boolean isParam= false;
        String[] str = null;
        try{
            str = req.getScores().split(":");
            if (null!=str && str.length !=2) {
                isParam = true;
            }
        }catch (Exception e) {
            isParam = true;
            logger.info("积分解析出错,当前积分信息:{}", req.getScores());
        }
        if (isParam) {
            return RecordScoreErrorEnum.RECORD_SCORE_LIST_ERROR_14.getId();
        }


        Integer scoreInt1 = Integer.parseInt(str[0]), scoreInt2 = Integer.parseInt(str[1]);
        if ((scoreInt1.intValue() > scoreInt2.intValue() && req.getIsWin() == GameConstants.SCHEDULE_WIN) ||
                (scoreInt1.intValue() < scoreInt2.intValue() && req.getIsWin() == GameConstants.SCHEDULE_LOSE) ||
                (scoreInt1.intValue() == scoreInt2.intValue() && req.getIsWin() == GameConstants.SCHEDULE_TIE)) {
            isParam = true;
        }
        if (!isParam) {
            return RecordScoreErrorEnum.RECORD_SCORE_LIST_ERROR_1.getId();
        }

        if (null!=tbGameEvent.getCurrentRoundId() && tbGameEvent.getCurrentRoundId().intValue() == -1) {
            return RecordScoreErrorEnum.RECORD_SCORE_LIST_ERROR_2.getId();
        }

        if (null == currentGameSchedules || currentGameSchedules.size() <1 || null == tbGameEvent) {
            return RecordScoreErrorEnum.RECORD_SCORE_LIST_ERROR_3.getId();
        }
        TbGameSchedule currentSchedule = tbGameScheduleMapper.selectByPrimaryKey(req.getGameScheduleId());
        if (scoreInt1.equals(scoreInt2)) {
            if (tbGameEvent.getCategoryId().intValue() == GameConstants. CATEGORY_ID_FOOTBALL){
                if (tbGameEvent.getGameSystemType().intValue() == GameSystemConfigEnum.CONFIG_GAME_TYPE_WASHED.getId()) {
                    return RecordScoreErrorEnum.RECORD_SCORE_LIST_ERROR_4.getId();
                }
                //校验混合赛 淘汰轮
                if (tbGameEvent.getGameSystemType().intValue() == GameSystemConfigEnum.CONFIG_GAME_TYPE_MIXED.getId()) {
                    TbGameRound tbGameRound = bizGameSystemDao.selectTbGameRound(currentSchedule.getGameRoundId());
                    if (tbGameRound.getRankTeamNum().intValue() != tbGameRound.getCurrentTeamNum().intValue()) {
                        return RecordScoreErrorEnum.RECORD_SCORE_LIST_ERROR_4.getId();
                    }
                }
            }else {
                return RecordScoreErrorEnum.RECORD_SCORE_LIST_ERROR_4.getId();
            }
        }
        if (null == currentSchedule || currentSchedule.getIsEnd().equals(GameConstants.IS_DELETE)) {
            return RecordScoreErrorEnum.RECORD_SCORE_LIST_ERROR_5.getId();
        }

        /*if (req.getType() == 0 && currentSchedule.getStatus().equals(GameConstants.RECORD_SUCCESS)) {
            return RecordScoreErrorEnum.RECORD_SCORE_LIST_ERROR_6.getId();
        }*/
        return result;
    }

    @Override
    public void updateSwissRound(TbGameRound tbGameRound, boolean isDouble) {
        logger.info("当前轮次id大小为:{},是否是双打比赛:{}", tbGameRound.getId(), isDouble);
        Gson gson = new Gson();
        Map<Integer, Set<Integer>> gameGroup = new HashMap<>();
        List<Integer> passTeam = new ArrayList<>();
        List<TbTeamDoubleAddendum> tbTeamDoubleAddendums = bizGameSystemDao.queryTbTeamDoubleAddendumList(tbGameRound.getGameEventId());
        Map<Integer, Integer> teamMap = new HashMap<>();
        if (CollectionUtils.isNotEmpty(tbTeamDoubleAddendums)) {
            for (TbTeamDoubleAddendum temp : tbTeamDoubleAddendums) {
                List<Integer> tempList =gson.fromJson(temp.getTeamIdGson() ,new TypeToken<List<Integer>>() {
                }.getType());

                for (Integer tempT : tempList) {
                    teamMap.put(tempT, temp.getId());
                }
            }
        }
        logger.info("当前轮次id大小为:{},是否是双打比赛:{},双打队伍映射表:{}", tbGameRound.getId(), isDouble, teamMap);
        Set<Integer> teamSet = new HashSet<>();
        List<VDefinedGameSchedule> vDefinedGameSchedules = bizGameSystemDao.selectVDefinedGameScheduleByGameRoundId(tbGameRound.getId(), null, null);
        Map<Integer, Set<Integer>> mapScheduleIds = new HashMap<>();
        Set<Integer> setScheduleId = new HashSet<>();
        for (VDefinedGameSchedule vDefinedGameSchedule : vDefinedGameSchedules) {
            setScheduleId = mapScheduleIds.get(vDefinedGameSchedule.getGameScheduleId());
            if (null == setScheduleId || setScheduleId.size() < 1) {
                setScheduleId = new HashSet<>();
            }
            if (null!=teamMap && teamMap.size() >0) {
                setScheduleId.add(teamMap.get(vDefinedGameSchedule.getEventTeamId()));
                teamSet.add(teamMap.get(vDefinedGameSchedule.getEventTeamId()));
            }else {
                setScheduleId.add(vDefinedGameSchedule.getEventTeamId());
                teamSet.add(vDefinedGameSchedule.getEventTeamId());
            }
            mapScheduleIds.put(vDefinedGameSchedule.getGameScheduleId(), setScheduleId);
        }
        logger.info("当前轮次id大小为:{},是否是双打比赛:{},当前轮次赛程下的对战双方信息:{}, 当前队伍信息:{}", tbGameRound.getId(), isDouble, mapScheduleIds, teamSet);
        for (Map.Entry<Integer, Set<Integer> > setTemp : mapScheduleIds.entrySet()) {
            List<Integer> temp = new ArrayList<>(setTemp.getValue());
            if(temp.size() == 1) {   //存在轮空的情况,这里放一个轮空id
                temp.add(0);
            }
            if (temp.get(0) > 0 && temp.get(1) > 0) {
                Set newTeam1 =  new HashSet();
                newTeam1.addAll(teamSet);
                Set newTeam2 =  new HashSet();
                newTeam2.addAll(teamSet);

                newTeam1.remove(temp.get(1));
                newTeam1.remove(temp.get(0));
                gameGroup.put(temp.get(0), newTeam1);

                newTeam2.remove(temp.get(0));
                newTeam2.remove(temp.get(1));
                gameGroup.put(temp.get(1), newTeam2);
            }else if(temp.get(0) > 0 && temp.get(1) == 0){
                Set newTeam1 =  new HashSet();
                newTeam1.addAll(teamSet);
                newTeam1.remove(temp.get(0));

                gameGroup.put(temp.get(0), newTeam1);
                passTeam.add(temp.get(0));
            }else if(temp.get(0) == 0 && temp.get(1) > 0){
                Set newTeam1 =  new HashSet();
                newTeam1.addAll(teamSet);
                newTeam1.remove(temp.get(1));

                gameGroup.put(temp.get(1), newTeam1);
                passTeam.add(temp.get(1));
            }else {
                logger.debug("同一轮次,两个队伍都轮空,出现异常. 赛程id:{},队伍集合:{}", setTemp.getKey(), temp);
            }
        }
        logger.info("当前轮次id大小为:{},是否是双打比赛:{},当前轮次轮空队伍集合:{},当前轮次可匹配队伍集合:{}", tbGameRound.getId(), isDouble, passTeam, gameGroup);
        TbGameRound round = new TbGameRound();
        round.setId(tbGameRound.getId());
        round.setPassTeam(gson.toJson(passTeam));
        round.setMatchTeam(gson.toJson(gameGroup));
        bizGameSystemDao.updateTbGameRound(round);
    }


    private void afterRecordScore(boolean isDispute, ReqRecordGameScheduleResult req, TbGameEvent tbGameEvent, Integer uid, Byte isWin){
        //存在争议调起推送
        if (isDispute) {
            //TODO
            List<Integer> uids = new ArrayList<>();
            uids.add(uid);
            gameMsgPush.pushRecordScoreDisputeMsgToUser(req, tbGameEvent, uids,new Date().getTime());
            gameMsgPush.gameScoreDisagree(tbGameEvent);
        }
        if (req.getType() == 0) {
            gameMQProduct.userRecordScoreMQ(req, uid);
        }
        //发起缓存更新
        try {
            officialGameCache.updateGameSchedule(req.getGameScheduleId(), tbGameEvent.getGameTeamType());
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        //更新当前用户为已录入比分 | 但是,管理员身份录入比分时,调起赛程结束标志
        bizGameSystemDao.updateUserGameScheduleFinish(req.getGameScheduleId(), req.getScores(), uid, req.getType() == 1 ? true : false, isWin);
    }

    @Override
    public boolean recordGameRoundTeamScore(TbGameEvent tbGameEvent, Integer curGameRoundId, List<TbGameRound> tbGameRoundList, List<TbGameEventTeam> tbGameEventTeamList) {
        if (null == tbGameEventTeamList) {
            tbGameEventTeamList = bizGameSystemDao.selectTbGameEventTeamByGameEventId(tbGameEvent.getId(), null, null, GameConstants.IS_NOT_DELETE);
        }
        List<TbGameRoundScore> tempCurRoundScore = bizGameSystemDao.selectTbGameRoundScoreByGameRoundId(curGameRoundId, null, null);
        if (null!=tempCurRoundScore && tempCurRoundScore.size()>0) {    //避免重复生成
            return true;
        }
        Collections.sort(tbGameRoundList, new Comparator<TbGameRound>() {   //按轮次的先后排序,id最大的为最后一轮
            public int compare(TbGameRound o1, TbGameRound o2) {
                return o1.getId().compareTo(o2.getId());
            }
        });
        Integer preGameRoundId = 0;
        int i=0;
        for (TbGameRound roundTemp : tbGameRoundList) {    //确定上一轮
            if (roundTemp.getId().equals(curGameRoundId)) {
                if (i>0) {
                    preGameRoundId = tbGameRoundList.get(i-1).getId();
                }
                break;
            }
            i++;
        }
        List<VDefinedGameSchedule> vDefinedGameSchedules = bizGameSystemDao.selectVDefinedGameScheduleByGameRoundId(curGameRoundId, null, null);
        if (null == vDefinedGameSchedules || vDefinedGameSchedules.size() < 1) {
            return false;
        }
        Map<Integer, TbGameRoundScore> teamScoreMsg = new HashMap<>();
        if (preGameRoundId!=0) {
            List<TbGameRoundScore> tbGameRoundScoreList = bizGameSystemDao.selectTbGameRoundScoreByGameRoundId(preGameRoundId, null, null);
            for (TbGameRoundScore tbGameRoundScore : tbGameRoundScoreList) {
                teamScoreMsg.put(tbGameRoundScore.getGameEventTeamId(), tbGameRoundScore);
            }
        }
        Map<Integer, Set<VDefinedGameSchedule>> mapSchedules = new HashMap<>();
        Set<VDefinedGameSchedule> setSchedule = new HashSet<>();
        for (VDefinedGameSchedule vDefinedGameSchedule : vDefinedGameSchedules) {
            setSchedule = mapSchedules.get(vDefinedGameSchedule.getGameScheduleId());
            if (null == setSchedule || setSchedule.size() < 1) {
                setSchedule = new HashSet<>();
            }
            setSchedule.add(vDefinedGameSchedule);
            mapSchedules.put(vDefinedGameSchedule.getGameScheduleId(), setSchedule);
        }
        List<Integer> curTeamIds = new ArrayList<>();
        List<Integer> firstRoundJoinedTeamIds = new ArrayList<>();
        for (Map.Entry<Integer, Set<VDefinedGameSchedule>> entry : mapSchedules.entrySet()) {
            TbGameRoundScore tbGameRoundScore = new TbGameRoundScore();
            tbGameRoundScore.setGameRoundId(curGameRoundId);
            int p = 1, w = 0, t = 0, f = 0;
            double s = 0.00;
            for (VDefinedGameSchedule vDefinedGameSchedule : entry.getValue()) {
                tbGameRoundScore.setGroupType(vDefinedGameSchedule.getGroup()); //插入分组信息
                s = GameScheduleScoreEnum.getScore(tbGameEvent.getCategoryId(), vDefinedGameSchedule.getIsWin(), vDefinedGameSchedule.getType());
                if (vDefinedGameSchedule.getType() == GameConstants.IS_NOT_DELETE) {  //主场
                    if (vDefinedGameSchedule.getIsWin() == GameConstants.SCHEDULE_WIN) {  //主场胜利
                        w=1;
                        t=0;
                        f=0;
                    } else if (vDefinedGameSchedule.getIsWin() == GameConstants.SCHEDULE_TIE) {   //客场胜利
                        w=0;
                        t=1;
                        f=0;
                    } else {     //平
                        w=0;
                        t=0;
                        f=1;
                    }
                }else if (vDefinedGameSchedule.getType() == GameConstants.IS_DELETE) {  //客场
                    if (vDefinedGameSchedule.getIsWin() == GameConstants.SCHEDULE_WIN) {  //主场胜利
                        w=0;
                        t=0;
                        f=1;
                    } else if (vDefinedGameSchedule.getIsWin() == GameConstants.SCHEDULE_TIE) {   //客场胜利
                        w=0;
                        t=1;
                        f=0;
                    } else {     //平
                        w=1;
                        t=0;
                        f=0;
                    }
                }else {
                }

                if (preGameRoundId!=0) {
                    TbGameRoundScore old = teamScoreMsg.get(vDefinedGameSchedule.getEventTeamId());
                    curTeamIds.add(vDefinedGameSchedule.getEventTeamId());
                    tbGameRoundScore.setProducts(p+old.getProducts());
                    tbGameRoundScore.setWins(w+old.getWins());
                    tbGameRoundScore.setTies(t+old.getTies());
                    tbGameRoundScore.setFails(f+old.getFails());
                    tbGameRoundScore.setScore(new BigDecimal(s+old.getScore()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                }else {
                    firstRoundJoinedTeamIds.add(vDefinedGameSchedule.getEventTeamId());
                    tbGameRoundScore.setProducts(p);
                    tbGameRoundScore.setWins(w);
                    tbGameRoundScore.setTies(t);
                    tbGameRoundScore.setFails(f);
                    tbGameRoundScore.setScore(new BigDecimal(s).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                }
                tbGameRoundScore.setGameEventTeamId(vDefinedGameSchedule.getEventTeamId());


                bizGameSystemDao.insertTbGameRoundScore(tbGameRoundScore);
            }
        }

        //比较队伍数目
        if (tbGameEventTeamList.size() > firstRoundJoinedTeamIds.size() && firstRoundJoinedTeamIds.size()>0) {
            List<Integer> tempIds = new ArrayList<>();
            for (TbGameEventTeam tbGameEventTeam:tbGameEventTeamList) {
                tempIds.add(tbGameEventTeam.getId());
            }
            tempIds.removeAll(firstRoundJoinedTeamIds);
            if (tempIds.size()>0) {
                for (Integer temp:tempIds) {
                    TbGameRoundScore tbGameRoundScore = new TbGameRoundScore();
                    tbGameRoundScore.setGameRoundId(curGameRoundId);
                    tbGameRoundScore.setGameEventTeamId(temp);
                    tbGameRoundScore.setProducts(0);
                    tbGameRoundScore.setWins(0);
                    tbGameRoundScore.setTies(0);
                    tbGameRoundScore.setFails(0);
                    tbGameRoundScore.setScore(0.00);
                    bizGameSystemDao.insertTbGameRoundScore(tbGameRoundScore);
                }
            }
        }


        //顺移完结的赛事分数
        for (Integer temp : curTeamIds) {
            teamScoreMsg.remove(temp);
        }

        if (null!=teamScoreMsg && teamScoreMsg.size() >0 ) {
            for (Map.Entry<Integer, TbGameRoundScore> temp : teamScoreMsg.entrySet()) {
                TbGameRoundScore tbGameRoundScore = temp.getValue();
                tbGameRoundScore.setId(null);
                tbGameRoundScore.setGameRoundId(curGameRoundId);
                bizGameSystemDao.insertTbGameRoundScore(tbGameRoundScore);
            }
        }

        try{
            // 抢签赛特殊处理 begin
            if (tbGameEvent.getGameSystemType().intValue() == GameSystemConfigEnum.CONFIG_GAME_TYPE_EIGHT_RULE.getId()) {
                List<TbGameSchedule> tbGameSchedules = bizGameSystemDao.selectTbGameScheduleByGameRoundId(curGameRoundId, 0, GameConstants.GAME_SCHEDULE_NUM);
                if (null != tbGameSchedules && tbGameSchedules.size() > 0) {
                    Gson gson = new Gson();
                    List<Integer> teamList = null;
                    for (TbGameSchedule tbGameSchedule: tbGameSchedules) {
                        String finalScore = tbGameSchedule.getFinalScore();
                        String [] scoreResluts = finalScore.split(":");
                        if (Integer.parseInt(scoreResluts[0]) < Integer.parseInt(scoreResluts[1])) {
                            if (null == teamList) {
                                teamList = gson.fromJson(tbGameSchedule.getTeamListIndex(), new TypeToken<List<Integer>>(){}.getType());
                            }

                            List<Integer> tempLocation = gson.fromJson(tbGameSchedule.getTeamMatchIndex(), new TypeToken<List<Integer>>() {
                            }.getType());

                            teamList = gameSystemServiceEight.eightChangeLocation(teamList, tempLocation);
                        }
                    }

                    if (null != teamList) {
                        String lastTeamJson = gson.toJson(teamList);
                        int reslut = bizGameSystemDao.updateTbGameScheduleByGameRoundId(lastTeamJson, curGameRoundId);

                        logger.info("updateTbGameScheduleByGameRoundId reslut:"+ reslut+" lastTeamJson:"+lastTeamJson+" curGameRoundId:"+curGameRoundId);
                    }
                    // end
                }
            }
        }catch (Exception e) {
            logger.error("recordGameRoundTeamScore is exception：", e);
        }

        return true;
    }

    @Override
    public APIResponse<?> updateGameScheduleTimeAndPlaceUnit(Integer uid, ReqGameSchedule reqGameSchedule) throws InvocationTargetException, IllegalAccessException {
        TbGameSchedule tbGameSchedule = tbGameScheduleMapper.selectByPrimaryKey(reqGameSchedule.getGameScheduleId());
        if (null == tbGameSchedule || tbGameSchedule.getId()<1) {
            return APIResponse.returnFail("该赛程不存在");
        }
        TbGameRound tbGameRound = bizGameSystemDao.selectTbGameRound(tbGameSchedule.getGameRoundId());
        if (null == tbGameRound || tbGameRound.getIsEnd() == GameConstants.IS_DELETE) {
            return APIResponse.returnFail("该赛程已结束,无法再次操作");
        }
        TbGameEvent tbGameEvent = bizGameSystemDao.selectTbGameEvent(tbGameRound.getGameEventId());
        TbGameSchedule schedule = new TbGameSchedule();
        schedule.setId(reqGameSchedule.getGameScheduleId());
        if (null!=reqGameSchedule.getPlaceUnitId()) {
            schedule.setPlaceUnitId(reqGameSchedule.getPlaceUnitId());
        }
        if (null != reqGameSchedule.getStartTime()) {
            schedule.setStartTime(new Date(reqGameSchedule.getStartTime()));
            if (null!=tbGameSchedule.getSingleTime() && tbGameSchedule.getSingleTime()>0) {
                schedule.setEndTime(DateUtils.addTime(new Date(reqGameSchedule.getStartTime()), tbGameSchedule.getSingleTime(), DateUtils.TIME_TYPE_MINUTE));
            }
        }
        if (null != reqGameSchedule.getEndTime()) {
            schedule.setEndTime(new Date(reqGameSchedule.getEndTime()));
        }
        bizGameSystemDao.updateTbGameSchedule(schedule);

        //MQ
        gameMQProduct.userScheduleUpdateMQ(tbGameSchedule, tbGameRound);

        //CACHE
        officialGameCache.updateGameSchedule(reqGameSchedule.getGameScheduleId(), tbGameEvent.getGameTeamType());

        return APIResponse.returnSuccess();
    }

    @Override
    public List<GameTeam> tbGameTeamTransferGameTeam(TbGameEvent event, List<TbGameEventTeam> list, Byte type) throws InvocationTargetException, IllegalAccessException {
        List<GameTeam> result = new ArrayList<>();
        List<Integer> uIds = new ArrayList<>();
        List<Integer> clubIds = new ArrayList<>();
        for (TbGameEventTeam team : list) {
            if (GameConstants.TEAM_TYPE_CLUB == type.byteValue()) {
                clubIds.add(team.getClubId());
            }else if (GameConstants.TEAM_TYPE_PERSON == type.byteValue()){
                uIds.add(team.getUid());
            }else {
            }
        }
        if (uIds!=null&&uIds.size()>0&&clubIds!=null&&clubIds.size()>0) {
            return null;
        }
        if (gameEventTransfer.getGameCategoryById(event.getGameCategoryType().intValue()).getMinNum() == 2
                && gameEventTransfer.getGameCategoryById(event.getGameCategoryType().intValue()).getMaxNum() == 2) {
            List<TbTeamDoubleAddendum> addendums = bizGameSystemDao.queryTbTeamDoubleAddendumList(event.getId());
            Map<Integer, User> tempUserMap = new HashMap<>();
            Map<Integer, RespUserInfoBase> mapUidMap = baseService.queryUserMsg(uIds);
            for (TbGameEventTeam tbGameEventTeam: list) {
                User user = new User();
                if (null!=mapUidMap.get(tbGameEventTeam.getUid())) {
                    BeanUtils.copyProperties(user,  mapUidMap.get(tbGameEventTeam.getUid()));
                    tempUserMap.put(tbGameEventTeam.getId(), user);
                }
            }
            Gson gson = new Gson();
            for (TbTeamDoubleAddendum tbTeamDoubleAddendum:addendums) {
                GameTeam gameTeam = new GameTeam();
                gameTeam.setType(type);
                List<User> usersTemp = new ArrayList<>();
                List<Integer> tempTeam = gson.fromJson(tbTeamDoubleAddendum.getTeamIdGson(), new TypeToken<List<Integer>>() {
                }.getType());
                for (Integer temp : tempTeam) {
                    usersTemp.add(tempUserMap.get(temp));
                }
                gameTeam.setId(tempTeam.get(0));
                gameTeam.setUserList(usersTemp);
                result.add(gameTeam);
            }
        }else {
            if (GameConstants.TEAM_TYPE_CLUB == type) {
                Map<Integer, RespClubPlainInfo> mapClubIdMap = baseService.queryClubMsg(clubIds);
                for (TbGameEventTeam tbGameEventTeam: list) {
                    GameTeam gameTeam = new GameTeam();
                    gameTeam.setId(tbGameEventTeam.getId());
                    gameTeam.setType(type);
                    if (null !=  mapClubIdMap.get(tbGameEventTeam.getClubId()) && mapClubIdMap.get(tbGameEventTeam.getClubId()).getClubId()>0) {
                        Club club = new Club();
                        BeanUtils.copyProperties(club, mapClubIdMap.get(tbGameEventTeam.getClubId()));
                        gameTeam.setClub(club);
                        result.add(gameTeam);
                    }
                }
            }else if (GameConstants.TEAM_TYPE_PERSON == type){
                Map<Integer, RespUserInfoBase> mapUidMap = baseService.queryUserMsg(uIds);
                for (TbGameEventTeam tbGameEventTeam: list) {
                    GameTeam gameTeam = new GameTeam();
                    gameTeam.setId(tbGameEventTeam.getId());
                    gameTeam.setType(type);
                    List<User> usersTemp = new ArrayList<>();
                    if (null !=  mapUidMap && null !=  mapUidMap.get(tbGameEventTeam.getUid()) && null!=mapUidMap.get(tbGameEventTeam.getUid()).getUid()) {
                        User user = new User();
                        BeanUtils.copyProperties(user,  mapUidMap.get(tbGameEventTeam.getUid()));
                        usersTemp.add(user);
                        gameTeam.setUserList(usersTemp);
                        result.add(gameTeam);
                    }
                }
            }else {
            }
        }
        return result;
    }

    @Override
    public List<RankGameTeam> tbGameTeamTransferGameTeamV4(TbGameEvent event, List<TbGameEventTeam> list, Byte type) throws InvocationTargetException, IllegalAccessException {
        List<RankGameTeam> result = new ArrayList<>();
        List<Integer> uIds = new ArrayList<>();
        List<Integer> clubIds = new ArrayList<>();
        for (TbGameEventTeam team : list) {
            if (GameConstants.TEAM_TYPE_CLUB == type.byteValue()) {
                clubIds.add(team.getClubId());
            }else if (GameConstants.TEAM_TYPE_PERSON == type.byteValue()){
                uIds.add(team.getUid());
            }else {
            }
        }
        if (uIds!=null&&uIds.size()>0&&clubIds!=null&&clubIds.size()>0) {
            return null;
        }
        if (gameEventTransfer.getGameCategoryById(event.getGameCategoryType().intValue()).getMinNum() == 2
                && gameEventTransfer.getGameCategoryById(event.getGameCategoryType().intValue()).getMaxNum() == 2) {
            List<TbTeamDoubleAddendum> addendums = bizGameSystemDao.queryTbTeamDoubleAddendumList(event.getId());
            Map<Integer, User> tempUserMap = new HashMap<>();
            Map<Integer, RespUserInfoBase> mapUidMap = baseService.queryUserMsg(uIds);
            for (TbGameEventTeam tbGameEventTeam: list) {
                User user = new User();
                if (null!=mapUidMap.get(tbGameEventTeam.getUid())) {
                    BeanUtils.copyProperties(user,  mapUidMap.get(tbGameEventTeam.getUid()));
                    tempUserMap.put(tbGameEventTeam.getId(), user);
                }
            }
            Gson gson = new Gson();
            for (TbTeamDoubleAddendum tbTeamDoubleAddendum:addendums) {
                RankGameTeam gameTeam = new RankGameTeam();
                gameTeam.setType(type);
                List<User> usersTemp = new ArrayList<>();
                List<Integer> tempTeam = gson.fromJson(tbTeamDoubleAddendum.getTeamIdGson(), new TypeToken<List<Integer>>() {
                }.getType());
                for (Integer temp : tempTeam) {
                    usersTemp.add(tempUserMap.get(temp));
                }
                gameTeam.setId(tempTeam.get(0));
                gameTeam.setUserList(usersTemp);
                result.add(gameTeam);
            }
        }else {
            if (GameConstants.TEAM_TYPE_CLUB == type) {
                Map<Integer, RespClubPlainInfo> mapClubIdMap = baseService.queryClubMsg(clubIds);
                for (TbGameEventTeam tbGameEventTeam: list) {
                    RankGameTeam gameTeam = new RankGameTeam();
                    gameTeam.setId(tbGameEventTeam.getId());
                    gameTeam.setType(type);
                    if (null !=  mapClubIdMap.get(tbGameEventTeam.getClubId()) && mapClubIdMap.get(tbGameEventTeam.getClubId()).getClubId()>0) {
                        Club club = new Club();
                        BeanUtils.copyProperties(club, mapClubIdMap.get(tbGameEventTeam.getClubId()));
                        gameTeam.setClub(club);
                        result.add(gameTeam);
                    }
                }
            }else if (GameConstants.TEAM_TYPE_PERSON == type){
                Map<Integer, RespUserInfoBase> mapUidMap = baseService.queryUserMsg(uIds);
                for (TbGameEventTeam tbGameEventTeam: list) {
                    RankGameTeam gameTeam = new RankGameTeam();
                    gameTeam.setId(tbGameEventTeam.getId());
                    gameTeam.setType(type);
                    List<User> usersTemp = new ArrayList<>();
                    if (null !=  mapUidMap && null !=  mapUidMap.get(tbGameEventTeam.getUid()) && null!=mapUidMap.get(tbGameEventTeam.getUid()).getUid()) {
                        User user = new User();
                        BeanUtils.copyProperties(user,  mapUidMap.get(tbGameEventTeam.getUid()));
                        usersTemp.add(user);
                        gameTeam.setUserList(usersTemp);
                        result.add(gameTeam);
                    }
                }
            }else {
            }
        }
        return result;
    }

    @Override
    public List<GameTeam> tbGameTeamTransferGameTeamV2(TbGameEvent event, List<TbGameEventScore> list, Byte type) throws InvocationTargetException, IllegalAccessException {
        List<GameTeam> result = new ArrayList<>();
        List<Integer> uIds = new ArrayList<>();
        List<Integer> clubIds = new ArrayList<>();
        Map<Integer, TbGameEventScore> teamToEventScoreMap = new HashMap<>();
        for (TbGameEventScore teamScore : list) {
            teamToEventScoreMap.put(teamScore.getGameEventTeamId(), teamScore);
            if (GameConstants.TEAM_TYPE_CLUB == type.byteValue()) {
                clubIds.add(teamScore.getClubId());
            }else if (GameConstants.TEAM_TYPE_PERSON == type.byteValue()){
                uIds.add(teamScore.getUid());
            }else {
            }
        }
        if (uIds!=null&&uIds.size()>0&&clubIds!=null&&clubIds.size()>0) {
            return null;
        }
        if (gameEventTransfer.getGameCategoryById(event.getGameCategoryType().intValue()).getMinNum() == 2
                && gameEventTransfer.getGameCategoryById(event.getGameCategoryType().intValue()).getMaxNum() == 2 && event.getGameSystemType().intValue() != GameSystemConfigEnum.CONFIG_GAME_TYPE_EIGHT_RULE.getId()) {
            List<TbTeamDoubleAddendum> addendums = bizGameSystemDao.queryTbTeamDoubleAddendumList(event.getId());
            Map<Integer, User> tempUserMap = new HashMap<>();
            Map<Integer, RespUserInfoBase> mapUidMap = baseService.queryUserMsg(uIds);
            for (TbGameEventScore teamScore: list) {
                User user = new User();
                if (null!=mapUidMap.get(teamScore.getUid())) {
                    BeanUtils.copyProperties(user,  mapUidMap.get(teamScore.getUid()));
                    tempUserMap.put(teamScore.getGameEventTeamId(), user);
                }
            }
            Gson gson = new Gson();
            for (TbTeamDoubleAddendum tbTeamDoubleAddendum:addendums) {
                GameTeam gameTeam = new GameTeam();
                gameTeam.setType(type);
                List<User> usersTemp = new ArrayList<>();
                List<Integer> tempTeam = gson.fromJson(tbTeamDoubleAddendum.getTeamIdGson(), new TypeToken<List<Integer>>() {
                }.getType());
                for (Integer temp : tempTeam) {
                    usersTemp.add(tempUserMap.get(temp));
                }
                gameTeam.setId(tempTeam.get(0));
                gameTeam.setUserList(usersTemp);
                gameTeam.setRank(teamToEventScoreMap.get(tempTeam.get(0)).getRank());
                result.add(gameTeam);
            }
        }else {
            if (GameConstants.TEAM_TYPE_CLUB == type) {
                Map<Integer, RespClubPlainInfo> mapClubIdMap = baseService.queryClubMsg(clubIds);
                for (TbGameEventScore teamScore: list) {
                    GameTeam gameTeam = new GameTeam();
                    gameTeam.setId(teamScore.getGameEventTeamId());
                    gameTeam.setType(type);
                    if (null !=  mapClubIdMap.get(teamScore.getClubId()) && mapClubIdMap.get(teamScore.getClubId()).getClubId()>0) {
                        Club club = new Club();
                        BeanUtils.copyProperties(club, mapClubIdMap.get(teamScore.getClubId()));
                        gameTeam.setClub(club);
                        gameTeam.setRank(teamToEventScoreMap.get(teamScore.getGameEventTeamId()).getRank());
                        result.add(gameTeam);
                    }
                }
            }else if (GameConstants.TEAM_TYPE_PERSON == type){
                Map<Integer, RespUserInfoBase> mapUidMap = baseService.queryUserMsg(uIds);
                for (TbGameEventScore teamScore: list) {
                    GameTeam gameTeam = new GameTeam();
                    gameTeam.setId(teamScore.getGameEventTeamId());
                    gameTeam.setType(type);
                    List<User> usersTemp = new ArrayList<>();
                    if (null !=  mapUidMap && null !=  mapUidMap.get(teamScore.getUid()) && null!=mapUidMap.get(teamScore.getUid()).getUid()) {
                        User user = new User();
                        BeanUtils.copyProperties(user,  mapUidMap.get(teamScore.getUid()));
                        usersTemp.add(user);
                        gameTeam.setUserList(usersTemp);
                        gameTeam.setRank(teamToEventScoreMap.get(teamScore.getGameEventTeamId()).getRank());
                        result.add(gameTeam);
                    }
                }
            }else {
            }
        }
        return result;
    }

    @Override
    public List<RankGameTeam> tbGameTeamTransferGameTeamV3(TbGameEvent event, List<TbGameEventScore> list, Byte type) throws InvocationTargetException, IllegalAccessException {
        List<RankGameTeam> result = new ArrayList<>();
        List<Integer> uIds = new ArrayList<>();
        List<Integer> clubIds = new ArrayList<>();
        Map<Integer, TbGameEventScore> teamToEventScoreMap = new HashMap<>();
        for (TbGameEventScore teamScore : list) {
            teamToEventScoreMap.put(teamScore.getGameEventTeamId(), teamScore);
            if (GameConstants.TEAM_TYPE_CLUB == type.byteValue()) {
                clubIds.add(teamScore.getClubId());
            }else if (GameConstants.TEAM_TYPE_PERSON == type.byteValue()){
                uIds.add(teamScore.getUid());
            }else {
            }
        }
        if (uIds!=null&&uIds.size()>0&&clubIds!=null&&clubIds.size()>0) {
            return null;
        }
        if (gameEventTransfer.getGameCategoryById(event.getGameCategoryType().intValue()).getMinNum() == 2
                && gameEventTransfer.getGameCategoryById(event.getGameCategoryType().intValue()).getMaxNum() == 2 && event.getGameSystemType().intValue() != GameSystemConfigEnum.CONFIG_GAME_TYPE_EIGHT_RULE.getId()) {
            List<TbTeamDoubleAddendum> addendums = bizGameSystemDao.queryTbTeamDoubleAddendumList(event.getId());
            Map<Integer, User> tempUserMap = new HashMap<>();
            Map<Integer, RespUserInfoBase> mapUidMap = baseService.queryUserMsg(uIds);
            for (TbGameEventScore teamScore: list) {
                User user = new User();
                if (null!=mapUidMap.get(teamScore.getUid())) {
                    BeanUtils.copyProperties(user,  mapUidMap.get(teamScore.getUid()));
                    tempUserMap.put(teamScore.getGameEventTeamId(), user);
                }
            }
            Gson gson = new Gson();
            for (TbTeamDoubleAddendum tbTeamDoubleAddendum:addendums) {
                RankGameTeam rankGameTeam = new RankGameTeam();
                rankGameTeam.setType(type);
                List<User> usersTemp = new ArrayList<>();
                List<Integer> tempTeam = gson.fromJson(tbTeamDoubleAddendum.getTeamIdGson(), new TypeToken<List<Integer>>() {
                }.getType());
                for (Integer temp : tempTeam) {
                    usersTemp.add(tempUserMap.get(temp));
                }
                rankGameTeam.setId(tempTeam.get(0));
                rankGameTeam.setUserList(usersTemp);
                rankGameTeam.setRank(teamToEventScoreMap.get(tempTeam.get(0)).getRank());
                rankGameTeam.setWinSchedules(teamToEventScoreMap.get(tempTeam.get(0)).getWins());
                rankGameTeam.setLoseSchedules(teamToEventScoreMap.get(tempTeam.get(0)).getFails());
                rankGameTeam.setMultipleScore(new BigDecimal(teamToEventScoreMap.get(tempTeam.get(0)).getOriginalScore() + teamToEventScoreMap.get(tempTeam.get(0)).getOpponentScore() / 10.0
                        + teamToEventScoreMap.get(tempTeam.get(0)).getSmallScore() / 100.0).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                result.add(rankGameTeam);
            }
        }else {
            if (GameConstants.TEAM_TYPE_CLUB == type) {
                Map<Integer, RespClubPlainInfo> mapClubIdMap = baseService.queryClubMsg(clubIds);
                for (TbGameEventScore teamScore: list) {
                    RankGameTeam rankGameTeam = new RankGameTeam();
                    rankGameTeam.setId(teamScore.getGameEventTeamId());
                    rankGameTeam.setType(type);
                    if (null !=  mapClubIdMap.get(teamScore.getClubId()) && mapClubIdMap.get(teamScore.getClubId()).getClubId()>0) {
                        Club club = new Club();
                        BeanUtils.copyProperties(club, mapClubIdMap.get(teamScore.getClubId()));
                        rankGameTeam.setClub(club);
                        rankGameTeam.setRank(teamToEventScoreMap.get(teamScore.getGameEventTeamId()).getRank());
                        rankGameTeam.setWinSchedules(teamToEventScoreMap.get(teamScore.getGameEventTeamId()).getWins());
                        rankGameTeam.setLoseSchedules(teamToEventScoreMap.get(teamScore.getGameEventTeamId()).getFails());
                        rankGameTeam.setMultipleScore(new BigDecimal(teamToEventScoreMap.get(teamScore.getGameEventTeamId()).getOriginalScore() + teamToEventScoreMap.get(teamScore.getGameEventTeamId()).getOpponentScore()/10.0
                                + teamToEventScoreMap.get(teamScore.getGameEventTeamId()).getSmallScore()/100.0).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                        result.add(rankGameTeam);
                    }
                }
            }else if (GameConstants.TEAM_TYPE_PERSON == type){
                Map<Integer, RespUserInfoBase> mapUidMap = baseService.queryUserMsg(uIds);
                for (TbGameEventScore teamScore: list) {
                    RankGameTeam rankGameTeam = new RankGameTeam();
                    rankGameTeam.setId(teamScore.getGameEventTeamId());
                    rankGameTeam.setType(type);
                    List<User> usersTemp = new ArrayList<>();
                    if (null !=  mapUidMap && null !=  mapUidMap.get(teamScore.getUid()) && null!=mapUidMap.get(teamScore.getUid()).getUid()) {
                        User user = new User();
                        BeanUtils.copyProperties(user,  mapUidMap.get(teamScore.getUid()));
                        usersTemp.add(user);
                        rankGameTeam.setUserList(usersTemp);
                        rankGameTeam.setRank(teamToEventScoreMap.get(teamScore.getGameEventTeamId()).getRank());
                        rankGameTeam.setWinSchedules(teamToEventScoreMap.get(teamScore.getGameEventTeamId()).getWins());
                        rankGameTeam.setLoseSchedules(teamToEventScoreMap.get(teamScore.getGameEventTeamId()).getFails());
                        rankGameTeam.setMultipleScore(new BigDecimal(teamToEventScoreMap.get(teamScore.getGameEventTeamId()).getOriginalScore() + teamToEventScoreMap.get(teamScore.getGameEventTeamId()).getOpponentScore()/10.0
                                + teamToEventScoreMap.get(teamScore.getGameEventTeamId()).getSmallScore()/100.0).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                        result.add(rankGameTeam);
                    }
                }
            }else {
            }
        }
        return result;
    }

    private List<Integer> eightChangeLocation(List<Integer> teamIds,  List<Integer> locationIndex){
        // swap the elements
        Collections.swap(teamIds, locationIndex.get(0), locationIndex.get(2));
        Collections.swap(teamIds, locationIndex.get(1), locationIndex.get(3));
        return teamIds;
    }
}
